package testJdk.random;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.junit.Test;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @version 1.0.0
 * Created by cyd on 2024-09-21 14:50:30
 * @ClassName : testJdk.random.TestRandom
 * @Description : 类描述
 */
public class TestRandom {

    @Test
    public void test01() {

        // 生成指定范围内的随机浮点数，其中min为最小值，max为最大值
        double value2 = ThreadLocalRandom.current().nextDouble(0.70, 0.75);
        BigDecimal valueBigDecimal2 = BigDecimal.valueOf(value2).setScale(2, RoundingMode.DOWN);
        System.out.println(valueBigDecimal2.toString());

        double value4 = ThreadLocalRandom.current().nextDouble(0.120, 0.130);
        BigDecimal valueBigDecimal4 = BigDecimal.valueOf(value4).setScale(3, RoundingMode.DOWN);
        System.out.println(valueBigDecimal4.toString());
    }

    @Test
    public void test2() {
        JSONObject obj = JSONUtil.createObj();
        obj.putOpt("clientId", "O3Dp8PgD7N1VHynkR2sQ")
                .putOpt("RSSI", 1)
                .putOpt("ambientHumidity", 1)
                .putOpt("ambientTemperature", 1)
                .putOpt("lightintensity", 1)
                .putOpt("pOW", 1)
                .putOpt("pressure", 1)
                .putOpt("rainfall", 1)
                .putOpt("windDirection", 1)
                .putOpt("windScale", 1)
                .putOpt("windSpeed", 1)
        ;
        System.out.println(obj.toJSONString(2));
    }
}
